﻿using System;
using System.Collections.Generic;
using CMS.Core.DataInterfaces;
using CMS.Core.Domain;

namespace CMS.Data
{
    public class CongDanDao : AbstractNHibernateDao<CongDan, System.Int32>, ICongDanDao
    {
        #region Create Instance
        private static CongDanDao instance = null;
        public static CongDanDao Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new CongDanDao();
                }
                return instance;
            }
        }
        #endregion

        /// <summary>
        /// Xóa các Công dân liên quan đến Tiếp dân
        /// </summary>
        /// <param name="TiepDanID"></param>
        /// <returns></returns>
        public bool DeleteByTiepDan(int TiepDanID)
        {
            try
            {
                String strQuery = @"From CongDan o Where o.MaTiepDanLookup.ID =:MaTiepDan";
                List<CongDan> list = NHibernateSessionManager.Instance.GetSession().CreateQuery(strQuery)
                        .SetParameter("MaTiepDan", TiepDanID)
                        .List<CongDan>() as List<CongDan>;
                foreach (CongDan item in list)
                {
                    this.Delete(item);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
